clear all
set more off
pause on
set trace off
set matsize 5000
set maxvar 32767
set seed 1234

foreach var in  dummieslab  estout tabout ivregress2 nearstat coefplot {		//Installing programs

	cap which `var'      // check whether -ado- is installed

	qui if _rc ssc install `var', replace // and get it if not
}

			********************************************************************************************************************
			***REPLICATION CODE FOR AHMED & STASAVAGE "ORIGINS OF EARLY DEMOCRACY", APSR APPENDIX TABLES A1 - A14 & FIGURE A1***
			********************************************************************************************************************

** Locals

	loc full_controls i.v1858 latitude longitude latitudeXlongitude v1914 v1915 v1916 v1917 v922 v183 

	loc country_controls anycouncil yst  caloric_variability sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr  kgatr kgatemp island mean_elev bio_cond plants animals landlocked geo_cond mean_rugg oceania cenlat cenlong ln_frontier_dist abslat area climate axis size africa europe asia americas 
	
/*---------------------------------------------------------------------------------------------------------------------------------------------------------------*/
	
***************
*** TABLES ****
***************

//1. TABEL A1 - Spatial Correlation and Varying Buffer Sizes

	estimates clear

	use analysis,clear
	
	lab var anycouncil "Any Council (0/1) - \emph{0 Km}"
	ren is_post1500MaxCal_gridcell_0km T

	drop if missing(latitude)
	drop if missing(longitude)
	drop if missing(T)
	
	nearstat latitude longitude, near( latitude longitude) distvar(distmetro) des(stat)
		
	loc controls  v1914 v1915 v1916 v1917 v922 
	
	gen xcut1=1
	gen ycut1=1
	gen const=1
	
	ren latitude xcord
	ren longitude ycord 
	
	estimates clear
	
	foreach y in anycouncil  {
			preserve
			
				drop if missing(`y')
				qui xi: reg `y' i.v1858 `controls' 
				predict fity if e(sample)
				gen residy  = fity-`y' 
				qui xi: reg T  i.v1858 `controls' if e(sample)
				predict fitx if e(sample)
				gen residx = fitx- T
				
				eststo E`y'B: x_ols xcord ycord xcut1 ycut1 residy residx const, xreg(2) coord(2)	
				
				matrix b=e(b)
				matrix b_coeff =  b[1,1]
							
				matrix V=e(V)
				matrix se=sqrt(V[1,1])
									
				matrix corr_se=sqrt(cov_dep[1,1])
				loc b_coeff=  b[1,1]
				loc corr_se = sqrt(cov_dep[1,1])
				matrix se_corr=(2*(1-normal(abs(`b_coeff'/`corr_se'))))
							
				matrix spa_err=sqrt(cov_dep[1,1])
				
				foreach stat in b_coeff se se_corr  spa_err {
					mat coln `stat' = T
					qui estadd mat `stat' = `stat'
				}
					
			restore
	}
	
	
	// Results Table

		local var "anycouncil"
		label var T `"`: variable label `var''"'	
		
		esttab E`var'B /*using TableA1.tex*/, cells("b_coeff(star fmt(3) pvalue(se_corr)) spa_err( par([ ]) fmt(4)) mu_diff(fmt(2)  pvalue(p)star)"  "se(par(( )) fmt(4)) ") ///
		keep(T)  booktabs eqlabels(none) f label nodep nonum noobs nonotes nomtitles starlevels(* 0.10 ** 0.05 *** 0.01) gaps replace ///
		collabels("\multicolumn{1}{c}{\specialcell{[1] \\ OLS}}" "\multicolumn{1}{c}{\specialcell{Conley \\ S.E.}}" ) 
	
	foreach x in 20 40 60 80 100 {
	
	use analysis,clear
	
	lab var anycouncil "Any Council (0/1) - \emph{`x' Km}"
	ren is_post1500MaxCal_gridcell_`x'km T

	drop if missing(latitude)
	drop if missing(longitude)
	drop if missing(T)
	
	*loc controls v1914 v1915 v1916 v1917 v183 ruggedness 
	
	loc controls  v1914 v1915 v1916 v1917 v922 
	
	gen xcut1=1
	gen ycut1=1
	gen const=1
	
	ren latitude xcord
	ren longitude ycord 
	
	estimates clear
	
	foreach y in anycouncil  {
			preserve
			
				drop if missing(`y')
				qui xi: reg `y' i.v1858 `controls' 
				predict fity if e(sample)
				gen residy  = fity-`y' 
				qui xi: reg T  i.v1858 `controls' if e(sample)
				predict fitx if e(sample)
				gen residx = fitx- T
				
				eststo E`y'B: x_ols xcord ycord xcut1 ycut1 residy residx const, xreg(2) coord(2)	
				
				matrix b=e(b)
				matrix b_coeff =  b[1,1]
							
				matrix V=e(V)
				matrix se=sqrt(V[1,1])
									
				matrix corr_se=sqrt(cov_dep[1,1])
				loc b_coeff=  b[1,1]
				loc corr_se = sqrt(cov_dep[1,1])
				matrix se_corr=(2*(1-normal(abs(`b_coeff'/`corr_se'))))
							
				matrix spa_err=sqrt(cov_dep[1,1])
				
				foreach stat in b_coeff se se_corr  spa_err {
					mat coln `stat' = T
					qui estadd mat `stat' = `stat'
				}
					
			restore
	}
	
	
	// Results Table

		local var "anycouncil"
		label var T `"`: variable label `var''"'	
		
		esttab E`var'B  /*using TableA1.tex*/, cells("b_coeff(star fmt(3) pvalue(se_corr)) spa_err( par([ ]) fmt(4)) mu_diff(fmt(2)  pvalue(p)star)"  "se(par(( )) fmt(4)) ") ///
		keep(T)  booktabs eqlabels(none) f label nodep nonum noobs nonotes nolines nomtitles starlevels(* 0.10 ** 0.05 *** 0.01) gaps append ///
		collabels(none) 
	}
		
//2. TABLE A2 - Crop Fixed Effects

		estimates clear
		
		use analysis,clear		

		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km `full_controls', r
		
		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil    if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc crop_FA "No"
		estadd	 loc princp_crop_FA "No"
		estadd	 loc major_crop_FA "No"
		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km `full_controls' i.v4, r
		
		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc princp_crop_FA "Yes"
		estadd	 loc major_crop_FA "No"
		
		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km `full_controls' i.v1123, r
		
		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil    if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc princp_crop_FA "No"
		estadd	 loc major_crop_FA "Yes"
		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km  latitude longitude latitudeXlongitude v1914 v1915 v1916 v1917 v922 v183   i.v1123 i.v4, r
		
		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "No"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc princp_crop_FA "Yes"
		estadd	 loc major_crop_FA "Yes"
		
		#d;
			esttab /*using TableA2.tex*/, replace se b(%9.3f) keep(is_post1500MaxCal_gridcell_20km)   eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			mtitles("\specialcell{[1]}" 
					"\specialcell{[2]}" 
					"\specialcell{[3]}"
					"\specialcell{[4]}" 
					"\specialcell{[5]}" 
					)
			mgroups("Any Council (\emph{=1 Council}, \emph{0 No Council})", pattern(1 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
					  ln_post1500MaxCal_20km "Caloric Suitability"
			)
			refcat (is_post1500MaxCal_gridcell_20km "\hline \\", nolabel)
			nonotes 
			stats(FE  add_controls princp_crop_FA major_crop_FA r2_a N depvarmean  , layout(@ @ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region Fixed Effects" "Controls" "Principal Crop Fixed Effects" "Major Agricultural Staple Fixed Effects" "Adj. R-squared" "Observations" "Dep. Var. Mean"))
			;
			
		#d cr
				
//3. TABLE A3 - Comparing SCCS & Ethnographic Atlas

		estimates clear

		use ethatlas, clear
		
		//. Renaming and Relabelling

			ren sccs T
						
		//. Generating Balance Table 

			eststo clear

		qui {
			foreach var of varlist gathering hunting fishing anhusb milking agricdep agricdepalt  polygyny polygynyalt clans  settlements compset locjuris  pater classdummy elections slavery property {
				
				//This stores the estimates
				eststo E`var'B:  xi: reg `var' T, robust 
				
				//This stores the treatment and control means, #obs and #clusters
				mat mu_C = _b[_cons]
				mat mu_T = _b[_cons] + _b[T]
				mat obs = e(N)
				mat clust = e(N_clust)
				foreach stat in mu_C mu_T obs {
					mat coln `stat' = T
					qui estadd mat `stat' = `stat'
				}
			}
		}

		//. Balance table

			local var "gathering"
			label var T `"`: variable label `var''"'	
			
			esttab E`var'B  /*using TableA3.tex*/, cells("mu_T(fmt(2)) mu_C(fmt(2)) b(fmt(2)star) se(fmt(2)par) obs(fmt(0))") ///
			keep(T)  booktabs eqlabels(none) f label nodep nonum noobs nonotes /*nolines*/ nomtitles  starlevels(* 0.10 ** 0.05 *** 0.01) gaps replace ///
			collabels("\multicolumn{1}{c}{SCCS}" "\multicolumn{1}{c}{Atlas}" "\multicolumn{1}{c}{Difference}" "\multicolumn{1}{c}{Std. Err.}" "\multicolumn{1}{c}{Obs.}") 

			foreach var of varlist hunting fishing anhusb milking agricdep agricdepalt  polygyny polygynyalt clans  settlements compset locjuris  pater classdummy elections slavery property {
				label var T `"`: variable label `var''"'
				esttab E`var'B  /*using TableA3.tex*/, cells("mu_T(fmt(2)) mu_C(fmt(2)) b(fmt(2)star) se(fmt(2)par) obs(fmt(0))") ///
					keep(T)  booktabs eqlabels(none) label f nodep nonum noobs nonotes nolines nomtitles starlevels(* 0.10 ** 0.05 *** 0.01) gaps append ///
					collabels(, none)
					 
			}	
			
	
//4. TABLE A4 - Trade and Caloric Variability

		estimates clear

		use analysis,clear		
			
		*Analysis
		
			estimates clear
		
			eststo: xi: reg v819 is_post1500MaxCal_gridcell_20km , r
			
			sum post1500MaxCal_gridcell_20km   if e(sample)==1
			local meancouncil = r(mean)
			sum v819    if e(sample)==1
			estadd scalar depvarmean=r(mean)
			
			estadd 	 loc FE "No"	
			estadd 	 loc controls "No"		
			estadd	 loc add_controls "No"
			
			eststo: xi: reg v819 is_post1500MaxCal_gridcell_20km i.v1858, r
			
			sum post1500MaxCal_gridcell_20km   if e(sample)==1
			local meancouncil = r(mean)
			sum v819   if e(sample)==1
			estadd scalar depvarmean=r(mean)
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "No"
			estadd	 loc add_controls "No"

			eststo: xi: reg v819 is_post1500MaxCal_gridcell_20km `full_controls', r
			
			sum post1500MaxCal_gridcell_20km   if e(sample)==1
			local meancouncil = r(mean)
			sum v819   if e(sample)==1
			estadd scalar depvarmean=r(mean)
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			eststo: xi: reg food_trade is_post1500MaxCal_gridcell_20km , r
			
			sum post1500MaxCal_gridcell_20km   if e(sample)==1
			local meancouncil = r(mean)
			sum food_trade   if e(sample)==1
			estadd scalar depvarmean=r(mean)
			
			estadd 	 loc FE "No"	
			estadd 	 loc controls "No"		
			estadd	 loc add_controls "No"
			
			eststo: xi: reg food_trade is_post1500MaxCal_gridcell_20km i.v1858, r
			
			sum post1500MaxCal_gridcell_20km   if e(sample)==1
			local meancouncil = r(mean)
			sum food_trade    if e(sample)==1
			estadd scalar depvarmean=r(mean)
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "No"
			estadd	 loc add_controls "No"
			
			eststo: xi: reg food_trade is_post1500MaxCal_gridcell_20km `full_controls', r
			
			sum post1500MaxCal_gridcell_20km   if e(sample)==1
			local meancouncil = r(mean)
			sum food_trade    if e(sample)==1
			estadd scalar depvarmean=r(mean)
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			#d;
				esttab /*using TableA4.tex*/, replace se b(%9.3f) keep(is_post1500MaxCal_gridcell_20km)   eqlabels(none) f  nodep nobaselevels nolines
				nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
				mtitles("\specialcell{[1]}" 
						"\specialcell{[2]}" 
						"\specialcell{[3]}"
						"\specialcell{[4]}" 
						"\specialcell{[5]}"
						"\specialcell{[6]}"
						"\specialcell{[7]}"
						"\specialcell{[8]}"
						"\specialcell{[9]}"
						"\specialcell{[10]}"
						)
				mgroups("Importance of Trade \%" "Trade as Food Source (0/1)", pattern(1 0 0  1 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
				varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
						  ln_post1500MaxCal_20km "Caloric Suitability"
				)
				refcat (is_post1500MaxCal_gridcell_20km "\hline \\", nolabel)
				nonotes 
				stats(FE add_controls r2_a N depvarmean  , layout(@ @ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region Fixed Effects"   "Controls" "Adj. R-squared" "Observations" "Dep. Var. Mean"))
				;
				
			#d cr
			

//5. TABLE A5 - Determinants of Caloric Variability & Council Presence 

	estimates clear
	
	** Ruggedness, Ecological diversity, num. of habitats
				
		use analysis, clear
			
			eststo: xi: reg is_post1500MaxCal_gridcell_20km ln_ruggedness `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			sum ruggedness   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1

			
			eststo: xi: reg is_post1500MaxCal_gridcell_20km v1888 `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"

			sum v1888   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1
			
			eststo: xi: reg is_post1500MaxCal_gridcell_20km ecodivfao `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			sum ecodivfao   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if e(sample)==1
			
			eststo: xi: reg is_post1500MaxCal_gridcell_20km river `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			sum ecodivfao   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if e(sample)==1
			
			eststo: xi: reg is_post1500MaxCal_gridcell_20km rainsd latitude longitude latitudeXlongitude v1916 v1917 v1913 v922 v183  v1915 i.v1858, r
				
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			sum rainsd   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if e(sample)==1

			eststo: xi: reg is_post1500MaxCal_gridcell_20km ln_ruggedness v1888 ecodivfao river rainsd latitude longitude latitudeXlongitude v1916 v1917 v1913 v922 v183  v1915 i.v1858, robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			sum ruggedness   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1
			

			**Any Council (0/1)
			
			eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km  `full_controls' if area<=20, robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			eststo: xi: reg anycouncil ln_ruggedness `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "No"

			sum ruggedness   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1
			
			eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km ln_ruggedness `full_controls', robust
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"			
			
			sum ruggedness   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if ruggedness<`meancouncil' & e(sample)==1
			
			eststo: xi: reg anycouncil v1888 `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			sum v1888   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1
			
			eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km v1888 `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			sum v1888   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1

			eststo: xi: reg anycouncil ecodivfao `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "No"
			
			sum ecodivfao   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1
			
			eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km ecodivfao `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"

			sum ecodivfao   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if e(sample)==1
			
			eststo: xi: reg anycouncil river `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"

			sum ecodivfao   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if e(sample)==1
			
			eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km river `full_controls', robust
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"

			sum ecodivfao   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if e(sample)==1
			
			
			eststo : xi: reg anycouncil rainsd latitude longitude latitudeXlongitude v1916 v1917 v1913 v922 v183  v1915 i.v1858, r
			
			sum rainsd   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1
			estadd scalar depvarmean=r(mean)
				
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			sum rainsd   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if rainsd<`meancouncil' & e(sample)==1
			
			
			eststo : xi: reg anycouncil rainsd is_post1500MaxCal_gridcell_20km latitude longitude latitudeXlongitude v1916 v1917 v1913 v922 v183  v1915 i.v1858, r
			
			sum rainsd   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil   if e(sample)==1
			estadd scalar depvarmean=r(mean)
				
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			estadd	 loc restricted_sample "No"

			eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km ln_ruggedness v1888 ecodivfao river rainsd latitude longitude latitudeXlongitude v1916 v1917 v1913 v922 v183  v1915 i.v1858, robust
						
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			estadd	 loc restricted_sample "No"
			
			sum post1500MaxCal_gridcell_20km   if e(sample)==1
			local meancouncil = r(mean)
			sum anycouncil    if e(sample)==1
			estadd scalar depvarmean=r(mean)
									
			#d;
				esttab /*using TableA5.tex*/, replace se b(%9.2f) keep(is_post1500MaxCal_gridcell_20km ln_ruggedness v1888 ecodivfao river rainsd )  
				order(is_post1500MaxCal_gridcell_20km ln_ruggedness v1888 ecodivfao river rainsd)  
				eqlabels(none) f  nodep nobaselevels nolines
				nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
				mtitles("\specialcell{[1]}" 
						"\specialcell{[2]}" 
						"\specialcell{[3]}"
						"\specialcell{[4]}" 
						"\specialcell{[5]}" 
						"\specialcell{[6]}" 
						"\specialcell{[7]}" 
						"\specialcell{[8]}" 
						"\specialcell{[9]}" 
						"\specialcell{[10]}"
						"\specialcell{[11]}" 
						"\specialcell{[12]}" 
						"\specialcell{[13]}" 
						"\specialcell{[14]}" 
						"\specialcell{[15]}" 
						"\specialcell{[16]}"
						"\specialcell{[17]}" 
						"\specialcell{[18]}" 

						)
				mgroups("Caloric Variability"  "Any Council (\emph{=1 Council}, \emph{0 No Council})", pattern(1 0 0 0 0 0 1 0 0 0 0 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
				varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
						  ln_ruggedness "ln(Ruggedness)"
						  rainsd "Rainfall (s.d)"

				)
				refcat (is_post1500MaxCal_gridcell_20km "\hline", nolabel)
				nonotes 
				stats(FE  add_controls r2_a N   , layout(@ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region F.E." "Controls" "Adj. R-squared" "Observations"))
				;
				
			#d cr
											
//6. TABLE A6 - Area and Community Size
		
		estimates clear
		
		use analysis, clear
	
		eststo: xi: reg  is_post1500MaxCal_gridcell_20km ln_area `full_controls', robust
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc restricted_sample "No"
		
		eststo: xi: reg  is_post1500MaxCal_gridcell_20km ln_area ln_ruggedness v1888 ecodivfao rainsd river `full_controls', robust
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"			
		estadd	 loc restricted_sample "No"
		
		eststo: xi: reg anycouncil  ln_area `full_controls', robust

		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc restricted_sample "No"
		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km  ln_area  `full_controls', robust
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc restricted_sample "No"

		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km  ln_area `full_controls' if area<=20, robust
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc restricted_sample "Yes"
		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km  ln_area ln_ruggedness v1888 ecodivfao rainsd river latitude longitude latitudeXlongitude v1916 v1917 v1913 v922 v183  v1915 i.v1858, robust

		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc restricted_sample "No"
		
		gen lnarea=ln_area
		
		eststo: xi: reg anycouncil c.is_post1500MaxCal_gridcell_20km##c.ln_area  i.v1858  c.latitude##c.lnarea c.longitude##c.lnarea c.latitudeXlongitude##c.lnarea c.rainsd##c.lnarea c.river##c.lnarea  c.v1915##c.lnarea c.v1916##c.lnarea c.v922##c.lnarea c.v1917##c.lnarea c.v183##c.lnarea c.ln_ruggedness##c.lnarea c.v1888##c.lnarea c.ecodivfao##c.lnarea, robust

		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		estadd	 loc restricted_sample "No"
		
		#d;
			esttab  /*using TableA6.tex*/, replace se b(%9.3f) keep(is_post1500MaxCal_gridcell_20km c.is_post1500MaxCal_gridcell_20km#c.ln_area ln_area ln_ruggedness v1888 ecodivfao rainsd river) order(ln_area is_post1500MaxCal_gridcell_20km c.is_post1500MaxCal_gridcell_20km#c.ln_area)   eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			mtitles("\specialcell{[1]}" 
						"\specialcell{[2]}" 
						"\specialcell{[3]}"
						"\specialcell{[4]}" 
						"\specialcell{[5]}" 
						"\specialcell{[6]}" 
						"\specialcell{[7]}" 
						"\specialcell{[8]}" 
						"\specialcell{[9]}" 
						"\specialcell{[10]}"
						"\specialcell{[11]}" 
						)
			mgroups("Caloric Variability"  "Any Council (\emph{=1 Council}, \emph{0 No Council})", pattern(1 0  1 0 0 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
						  ln_post1500MaxCal_20km "Caloric Suitability"
						  ln_ruggedness "Log - Ruggedness"
						  ln_area "Log -  Area"
						  rainsd "Rainfall (s.d)"
						  c.is_post1500MaxCal_gridcell_20km#c.ln_area "Caloric Variability $\times$ Log - Area"
			)
			refcat (ln_area "\hline", nolabel)
			nonotes 
			stats(FE add_controls restricted_sample r2_a N   , layout(@ @ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region Fixed Effects" "Controls" "Area $\le$ 20km sample" "Adj. R-squared" "Observations"))
			;
				
		#d cr
		
//7. TABLE A7 - Pre-1500 Caloric Variability & Impact of Columbian Exchange

		estimates clear

		use analysis,clear
		
		eststo: xi: reg anycouncil  is_pre1500MaxCal_gridcell_20km `full_controls' i.v1858, r
			
		sum pre1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil    if e(sample)==1
		estadd scalar depvarmean=r(mean)
				
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
	
		
		forval x=40(20)80 {

			preserve
			
				drop  is_pre1500MaxCal_gridcell_20km
				ren is_pre1500MaxCal_gridcell_`x'km  is_pre1500MaxCal_gridcell_20km
				
				eststo: xi: reg anycouncil  is_pre1500MaxCal_gridcell_20km `full_controls' i.v1858, r
			
				sum pre1500MaxCal_gridcell_20km   if e(sample)==1
				local meancouncil = r(mean)
				sum anycouncil    if e(sample)==1
				estadd scalar depvarmean=r(mean)
				
				estadd 	 loc FE "Yes"	
				estadd 	 loc controls "Yes"
				estadd	 loc add_controls "Yes"
				
			restore
		}
	
		#d;
			esttab /*using TableA7.tex*/, keep(is_pre1500MaxCal_gridcell_20km) order(is_pre1500MaxCal_gridcell_20km)  replace se b(%9.3f)   eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			mtitles("\specialcell{[1] \\ (20km)}" 
					"\specialcell{[2] \\ (40km)}" 
					"\specialcell{[3] \\ (60km)}"
					"\specialcell{[4] \\ (80km)}" 
					"\specialcell{[5]}" 
					"\specialcell{[6]}" 
					"\specialcell{[7]}" 
					"\specialcell{[8]}" 

					)
			mgroups("Any Council (\emph{=1 Council}, \emph{0 No Council})", pattern(1 0 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			varlabels(is_pre1500MaxCal_gridcell_20km "Pre-Columbian Caloric Variability"
			)
			refcat (is_pre1500MaxCal_gridcell_20km "\hline", nolabel)
			nonotes 
			stats( r2_a N   , layout(@ @)  fmt(a3 a3 ) labels(  "Adj. R-squared" "Observations" ))
			;
			
		#d cr
		
		
		estimates clear
		
		forval x=20(20)80 {
		
			preserve
			
				drop  is_pre1500MaxCal_gridcell_20km
				ren is_prepost_variability_`x'km  is_pre1500MaxCal_gridcell_20km
				
				eststo: xi: reg anycouncil  is_pre1500MaxCal_gridcell_20km `full_controls' i.v1858, r
				
				sum pre1500MaxCal_gridcell_`x'km   if e(sample)==1
				local meancouncil = r(mean)
				sum anycouncil    if e(sample)==1
				estadd scalar depvarmean=r(mean)
				
				estadd 	 loc FE "Yes"	
				estadd 	 loc controls "Yes"
				estadd	 loc add_controls "Yes"
			
			restore
		
		}
		
		#d;
			esttab /*using TableA7.tex*/, keep(is_pre1500MaxCal_gridcell_20km) order(is_pre1500MaxCal_gridcell_20km)  append se b(%9.3f)   eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			nomtitles
			refcat (is_pre1500MaxCal_gridcell_20km, nolabel)
			varlabels(is_pre1500MaxCal_gridcell_20km "Columbian Exchange: $\Delta$ Caloric Variability"
			)
			nonotes 
			stats(FE add_controls r2_a N   depvarmean, layout(@ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region Fixed Effects" "Controls"  "Adj. R-squared" "Observations" "Dep. Var. Mean"))
			;
			
		#d cr
		
//8.  TABLE A8  - Agricultural Risk  & Risk Sharing 

		estimates clear

		use analysis,clear
		
		gen nonkinfoodshare=non_kin_foodshare
		gen foodscarcity=food_scarcity		
		gen variabilityXscarcity=is_post1500MaxCal_gridcell_20km*foodscarcity
		gen variabilityXsharing=is_post1500MaxCal_gridcell_20km*non_kin_foodshare
		
		eststo: xi: reg anycouncil  food_scarcity `full_controls', r
		
		sum anycouncil   if e(sample)==1
		estadd scalar controlmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km  food_scarcity `full_controls', r

		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil  if e(sample)==1
		estadd scalar controlmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil variabilityXscarcity food_scarcity is_post1500MaxCal_gridcell_20km  i.v1858  c.latitude##c.foodscarcity c.longitude##c.foodscarcity c.latitudeXlongitude##c.foodscarcity c.v1914##c.foodscarcity c.v1915##c.foodscarcity c.v1916##c.foodscarcity c.v922##c.foodscarcity c.v1917##c.foodscarcity c.v183##c.foodscarcity, r

		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   
		estadd scalar controlmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"

		eststo: xi: reg anycouncil  non_kin_foodshare `full_controls', r
		
		sum anycouncil   if e(sample)==1
		estadd scalar controlmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km  non_kin_foodshare `full_controls', r

		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil  if e(sample)==1 
		estadd scalar controlmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		eststo: xi: reg anycouncil variabilityXsharing is_post1500MaxCal_gridcell_20km non_kin_foodshare  i.v1858  c.latitude##c.nonkinfoodshare c.longitude##c.nonkinfoodshare c.latitudeXlongitude##c.nonkinfoodshare c.v1914##c.nonkinfoodshare c.v1915##c.nonkinfoodshare c.v1916##c.nonkinfoodshare c.v922##c.nonkinfoodshare c.v1917##c.nonkinfoodshare c.v183##c.nonkinfoodshare, r

		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil    if e(sample)==1
		estadd scalar controlmean=r(mean)		
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		#d;
			esttab /*using TableA8.tex*/, replace se b(%9.3f) keep(is_post1500MaxCal_gridcell_20km food_scarcity non_kin_foodshare variabilityXscarcity variabilityXsharing)   
			order(food_scarcity non_kin_foodshare is_post1500MaxCal_gridcell_20km  variabilityXscarcity variabilityXsharing)
			eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			mtitles("\specialcell{[1]}" 
					"\specialcell{[2]}" 
					"\specialcell{[3]}"
					"\specialcell{[4]}" 
					"\specialcell{[5]}" 
					"\specialcell{[6]}" 

					)
			mgroups("\specialcell{Any Council (0/1) \\ \textit{Agricultural Risk}}" "\specialcell{Any Council (0/1) \\ \textit{Risk Sharing}}", pattern(1 0 0 1 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
					  food_scarcity "Food Scarcity (0/1)"
					  non_kin_foodshare "Non-kin food sharing (0/1)" 
					  variabilityXsharing "Non-kin food sharing (0/1) $\times$ Caloric Variability"
					  variabilityXscarcity "Food Scarcity (0/1) $\times$ Caloric Variability"

			)
			refcat (food_scarcity "\hline \\", nolabel)
			nonotes 
			stats(FE add_controls r2_a N controlmean  , layout(@ @ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region Fixed Effects" "Controls" "Adj. R-squared" "Observations" "Dep. Var. Mean"))
			;
			
		#d cr
		
//9.  TABLE A9 - Centralized Society & Council Presence 

		estimates clear

		use analysis,clear
		
		gen variabilityXcentral=is_post1500MaxCal_gridcell_20km*central_society
		
		eststo: xi: reg anycouncil  central_society `full_controls', r
		
		sum anycouncil  if e(sample)==1  
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil is_post1500MaxCal_gridcell_20km  central_society `full_controls', r

		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil variabilityXcentral central_society is_post1500MaxCal_gridcell_20km  c.latitude##central_society c.longitude##central_society c.latitudeXlongitude##central_society c.v1914##central_society c.v1915##central_society c.v1916##central_society c.v922##central_society c.v1917##central_society c.v183##central_society, r

		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil  if e(sample)==1  
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"

		
		
		#d;
			esttab /*using TableA9.tex*/, replace se b(%9.3f) keep(is_post1500MaxCal_gridcell_20km central_society variabilityXcentral)   
			order(central_society   is_post1500MaxCal_gridcell_20km variabilityXcentral)
			eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			mtitles("\specialcell{[1]}" 
					"\specialcell{[2]}" 
					"\specialcell{[3]}"
					"\specialcell{[4]}" 
					"\specialcell{[5]}" 
					"\specialcell{[6]}" 

					)
			mgroups("\specialcell{Any Council (0/1) \\ \textit{Centralized Society}}", pattern(1 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
					  central_society "Centralized Society (0/1)"
					  variabilityXcentral "Central Society (0/1) $\times$ Caloric Variability"
			)
			refcat (central_society "\hline", nolabel)
			nonotes 
			stats(FE add_controls r2_a N depvarmean  , layout(@ @ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region Fixed Effects" "Controls" "Adj. R-squared" "Observations" "Dep. Var. Mean"))
			;
			
		#d cr
		

//10.  TABLE A10 - Roots/Tubers Vs Cereals

		estimates clear

		use analysis,clear
		
		gen variabilityXroots=is_post1500MaxCal_gridcell_20km*roots_tubers
		
		
		eststo: xi: reg anycouncil  roots_tubers `full_controls', r
		
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil  is_post1500MaxCal_gridcell_20km roots_tubers `full_controls', r
		
		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil  variabilityXroots  is_post1500MaxCal_gridcell_20km roots_tubers i.v1858 c.latitude##roots_tubers c.longitude##roots_tubers c.latitudeXlongitude##roots_tubers c.v1914##roots_tubers c.v1915##roots_tubers c.v1916##roots_tubers c.v922##roots_tubers c.v1917##roots_tubers c.v183##roots_tubers, r

		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		eststo: xi: reg anycouncil  is_roots_tubers `full_controls', r
		
		sum roots_suit_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil  if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil is_cereal `full_controls', r
		
		sum cereal_suit_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil  if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil  is_roots_tubers is_post1500MaxCal_gridcell_20km `full_controls', r
		
		sum roots_suit_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		eststo: xi: reg anycouncil is_cereal  is_post1500MaxCal_gridcell_20km `full_controls', r
		
		sum cereal_suit_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		#d;
			esttab /*using TableA10.tex*/, replace se b(%9.3f) keep( roots_tubers is_post1500MaxCal_gridcell_20km variabilityXroots  is_roots_tubers is_cereal)   
			order(roots_tubers is_post1500MaxCal_gridcell_20km variabilityXroots  is_roots_tubers is_cereal)
			eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			mtitles("\specialcell{[1]}" 
					"\specialcell{[2]}" 
					"\specialcell{[3]}"
					"\specialcell{[4]}" 
					"\specialcell{[5]}" 
					"\specialcell{[6]}" 
					"\specialcell{[7]}"

					)
			mgroups("\specialcell{Any Council (0/1) \\ \textit{Roots/Tubers Principal Crop}}" "\specialcell{Any Council (0/1) \\ \textit{Roots/Tubers Vs Cereal Suitability}}", pattern(1 0 0 1 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
					  roots_tubers "Roots/Tubers Principal Crop (0/1)"
					  is_roots_tubers "Roots/Tubers Variability" 
					  is_cereal "Cereal Variability"
					  variabilityXroots "Roots/Tubers (0/1) $\times$ Caloric Variability"

			)
			refcat (roots_tubers "\hline", nolabel)
			nonotes 
			stats(FE add_controls r2_a N depvarmean  , layout(@ @ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region Fixed Effects" "Controls" "Adj. R-squared" "Observations" "Dep. Var. Mean"))
			;
			
		#d cr
		
//11.  Table A11 - Ethnolinguistic Diversity & Communal Heterogeneity

		estimates clear

		use analysis,clear
				
		eststo: xi: reg anycouncil  v1832educa3 , r
		
		sum anycouncil    if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "No"	
		estadd 	 loc controls "No"
		estadd	 loc add_controls "No"
				
		eststo: xi: reg anycouncil  v1832educa3 `full_controls', r
		
		sum anycouncil    if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		eststo: xi: reg anycouncil v1832educa3  is_post1500MaxCal_gridcell_20km `full_controls', r
		
		sum anycouncil    if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		eststo: xi: reg anycouncil v1832educa3##c.is_post1500MaxCal_gridcell_20km  i.v1858   c.latitude##v1832educa3 c.longitude##v1832educa3 c.latitudeXlongitude##v1832educa3 c.v1914##v1832educa3 c.v1915##v1832educa3 c.v1916##v1832educa3 c.v922##v1832educa3 c.v1917##v1832educa3 c.v183##v1832educa3, r
		
		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		eststo: xi: reg anycouncil  v788 , r
		
		sum anycouncil   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "No"	
		estadd 	 loc controls "No"
		estadd	 loc add_controls "No"
				
		eststo: xi: reg anycouncil  v788 `full_controls', r
		
		sum anycouncil    if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		eststo: xi: reg anycouncil v788  is_post1500MaxCal_gridcell_20km `full_controls', r
		
		sum anycouncil if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		eststo: xi: reg anycouncil v788##c.is_post1500MaxCal_gridcell_20km  i.v1858   c.latitude##v788 c.longitude##v788 c.latitudeXlongitude##v788 c.v1914##v788 c.v1915##v788 c.v1916##v788 c.v922##v788 c.v1917##v788 c.v183##v788, r
		
		sum post1500MaxCal_gridcell_20km   if e(sample)==1
		local meancouncil = r(mean)
		sum anycouncil  if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
	
		#d;
			esttab /*using TableA11.tex*/, replace se b(%9.3f) keep(v1832educa3 v788 is_post1500MaxCal_gridcell_20km 1.v1832educa3 2.v1832educa3 1.v1832educa3#c.is_post1500MaxCal_gridcell_20km  2.v1832educa3#c.is_post1500MaxCal_gridcell_20km  2.v788  3.v788 2.v788#c.is_post1500MaxCal_gridcell_20km  3.v788#c.is_post1500MaxCal_gridcell_20km)   
			order(v1832educa3 v788 is_post1500MaxCal_gridcell_20km 1.v1832educa3 2.v1832educa3 1.v1832educa3#c.is_post1500MaxCal_gridcell_20km  2.v1832educa3#c.is_post1500MaxCal_gridcell_20km  2.v788  3.v788 2.v788#c.is_post1500MaxCal_gridcell_20km  3.v788#c.is_post1500MaxCal_gridcell_20km)
			eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			mtitles("\specialcell{[1]}" 
					"\specialcell{[2]}" 
					"\specialcell{[3]}"
					"\specialcell{[4]}" 
					"\specialcell{[5]}" 
					"\specialcell{[6]}" 
					"\specialcell{[7]}" 
					"\specialcell{[8]}" 
					)
			mgroups("Any Council (0/1)" , pattern(1 0 0 0 0 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
					  v1832educa3 "Contact Languages (\textit{none, one, 2 or more})"
					  v788 "Community links (\textit{no links, some links, many links})" 
					  1.v1832educa3 "1 Contact Language change present (0/1)"
					  2.v1832educa3 "2 or more Contact Language changes present (0/1)"
					  2.v788#c.is_post1500MaxCal_gridcell_20km  "Some links (0/1) $\times$ Caloric Variability"
					  3.v788#c.is_post1500MaxCal_gridcell_20km "Many links (0/1) $\times$ Caloric Variability"
					  1.v1832educa3#c.is_post1500MaxCal_gridcell_20km "1 contact lang. change (0/1) $\times$ Caloric Variability"
					  2.v1832educa3#c.is_post1500MaxCal_gridcell_20km "2 or more contact lang. changes (0/1) $\times$ Caloric Variability"
					  

			)
			refcat (v1832educa3 "\hline", nolabel)
			nonotes 
			stats(FE add_controls r2_a N depvarmean  , layout(@ @ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Region Fixed Effects" "Controls" "Adj. R-squared" "Observations" "Dep. Var. Mean"))
			;
			#d cr
			
		
		
//12. TABLE A12 - Ordered Logit

		estimates clear

		use analysis,clear
	
		eststo: xi: ologit v157 is_post1500MaxCal_gridcell_20km is_post1500MaxCal_20km , r or
		
		sum v157   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "No"	
		estadd 	 loc controls "No"
		estadd	 loc add_controls "No"
		
		
		eststo: xi: ologit v157 is_post1500MaxCal_gridcell_20km is_post1500MaxCal_20km i.v1858, r or
		
		sum v157   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "Yes"	
		estadd 	 loc controls "No"
		estadd	 loc add_controls "No"
		
		
		eststo: xi: ologit v157 is_post1500MaxCal_gridcell_20km is_post1500MaxCal_20km latitude longitude latitudeXlongitude v1914 v1915 v1916 v1917 v922 v183 , r or
		
		sum v157   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "No"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		

		
		eststo: xi: ologit v157 is_post1500MaxCal_gridcell_20km is_post1500MaxCal_20km `full_controls', r or
		
		sum v157   if e(sample)==1
		estadd scalar depvarmean=r(mean)
		
		estadd 	 loc FE "No"	
		estadd 	 loc controls "Yes"
		estadd	 loc add_controls "Yes"
		
		
		#d;
			esttab /*using TableA12.tex*/, replace se b(%9.3f) keep(is_post1500MaxCal_gridcell_20km is_post1500MaxCal_20km)   
			eqlabels(none) f  nodep nobaselevels nolines
			nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
			mtitles("\specialcell{[1]}" 
					"\specialcell{[2]}" 
					"\specialcell{[3]}"
					"\specialcell{[4]}" 
					"\specialcell{[5]}" 
					"\specialcell{[6]}" 

					)
			mgroups("\specialcell{Political Integration}", pattern(1 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
			varlabels(is_post1500MaxCal_gridcell_20km "Caloric Variability"
					  is_post1500MaxCal_20km "Caloric Suitability"
			)
			refcat (is_post1500MaxCal_gridcell_20km "\hline"
					, nolabel)
			stats(FE  add_controls r2_a N , layout(@ @ @ @)  fmt(a3 a3 a3 a3) labels("Region Fixed Effects" "Controls" "Adj. R-squared" "Observations" ))

			;
			
		#d cr		
		
//13. TABLE A13 - Neolithic Transition, Diffusion of Agriculture, and Council Presence 

	estimates clear
	
	use analysis,clear
				
		ren is_post1500MaxCal_gridcell_20km caloric_variability
			
			foreach v of loc country_controls {
				local l`v' : variable label `v'
				if `"`l`v''"' == "" {
 				local l`v' "`v'"
				}
			}
			
			collapse (mean) `country_controls', by(country)
		
			foreach v of loc country_controls {
				label var `v' "`l`v''"
			}
		
			gen ystXcaloric_variability=yst*caloric_variability
			
			eststo: xi: reg anycouncil yst , robust 
			
			estadd 	 loc FE "No"	
			estadd 	 loc controls "No"
			estadd	 loc add_controls "No"
			
			
			eststo: xi: reg anycouncil yst  africa europe asia americas , robust 
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "No"
			estadd	 loc add_controls "No"
			
			eststo: xi: reg anycouncil  sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr africa europe asia americas , robust 

			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "No"
			estadd	 loc add_controls "No"
			
			eststo: xi: reg anycouncil  sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr ln_frontier_dist abslat area climate axis size plants animals mean_elev mean_rugg kgatr kgatemp landlocked island africa europe asia americas , robust 

			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			eststo: xi: reg anycouncil yst sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr ln_frontier_dist abslat area climate axis size plants animals mean_elev mean_rugg kgatr kgatemp landlocked island africa europe asia americas , robust 

			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
				
			eststo: xi: reg anycouncil yst caloric_variability, robust 
			
			estadd 	 loc FE "No"	
			estadd 	 loc controls "No"
			estadd	 loc add_controls "No"
			
			
			eststo: xi: reg anycouncil yst caloric_variability  africa europe asia americas , robust 
			
			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "No"
			estadd	 loc add_controls "No"
			
			
			eststo: xi: reg anycouncil  caloric_variability sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr  africa europe asia americas , robust 

			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "No"
			estadd	 loc add_controls "No"
			
			eststo: xi: reg anycouncil  caloric_variability sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr ln_frontier_dist abslat area climate axis size plants animals mean_elev mean_rugg kgatr kgatemp landlocked island africa europe asia americas , robust 

			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			eststo: xi: reg anycouncil yst caloric_variability sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr ln_frontier_dist abslat area climate axis size plants animals mean_elev mean_rugg kgatr kgatemp landlocked island africa europe asia americas , robust 

			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
			eststo: xi: reg anycouncil  yst caloric_variability ystXcaloric_variability sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr ln_frontier_dist abslat area climate axis size plants animals mean_elev mean_rugg kgatr kgatemp landlocked island africa europe asia americas , robust 

			estadd 	 loc FE "Yes"	
			estadd 	 loc controls "Yes"
			estadd	 loc add_controls "Yes"
			
		
			#d;
				esttab /*using TableA13.tex*/, replace se b(%9.3f) keep(yst  caloric_variability ystXcaloric_variability  sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr)  
				order(yst  caloric_variability ystXcaloric_variability sd_intermonthly_1901_2000 sd_intermonthly_1901_2000_sqr)  
				eqlabels(none) f  nodep nobaselevels nolines
				nonum noobs nonotes starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
				mtitles("\specialcell{[1]}" 
						"\specialcell{[2]}" 
						"\specialcell{[3]}"
						"\specialcell{[4]}" 
						"\specialcell{[5]}" 
						"\specialcell{[6]}" 
						"\specialcell{[7]}" 
						"\specialcell{[8]}" 
						"\specialcell{[9]}" 
						"\specialcell{[10]}" 
						"\specialcell{[11]}" 

						)
				mgroups("Any Council [0,1]", pattern(1 0 0 0 0 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
				varlabels(caloric_variability "Caloric Variability"
						  yst "Time elapsed (1000 yrs) - Neolithic Revolution"
						  ystXcaloric_variability "Time elapsed $\times$ Caloric Variability"
						  sd_intermonthly_1901_2000 "Intermonth temperature s.d. 1901 - 2000"
						  sd_intermonthly_1901_2000_sqr "(Intermonth temperature s.d. 1901 - 2000)$^2$"

				)		 
				refcat (yst "\hline", nolabel)
				nonotes 
				stats(FE  add_controls r2_a N   , layout(@ @ @ @)  fmt(a3 a3 a3 a3 a3) labels("Continent Fixed Effects" "Controls" "Adj. R-squared" "Observations"))
				;
				
			#d cr
			
//14. TABLE 14 - Early Councils & Executive Constraints Today

	estimates clear

	use polity, clear

	eststo: xi:  reg xconst anycouncil `full_controls', robust
	
	estadd 	 loc controls "Yes"	
	estadd 	 loc FE "Yes"	

	eststo: xi: reg xconst v157 `full_controls', robust
	
	estadd 	 loc controls "Yes"	
	estadd 	 loc FE "Yes"

	eststo: xi: reg xconst anycouncil v157 `full_controls', robust
	
	estadd 	 loc controls "Yes"	
	estadd 	 loc FE "Yes"

	
	#d;
		esttab /*using TableA14.tex*/, replace se b(%9.3f) keep(v157 anycouncil)   eqlabels(none) f  nodep nobaselevels nolines
		nonum noobs nonotes  starlevels(* 0.10 ** 0.05 *** 0.01) label gaps collabels(, none) nocons 
		mtitles("\specialcell{[1]}" 
				"\specialcell{[2]}" 
				"\specialcell{[3]}"
				)	
		refcat (anycouncil "\hline", nolabel)
		nonotes 
		mgroups("Polity Index", pattern(1 0 0)  prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) 
		stats(FE controls r2_a N  , layout(@ @ @)  fmt(a3 a3 a3) labels("Region Fixed Effects" "Controls"  "Adj. R-squared" "Observations"))
		varlabels(ln_post1500MaxCal_gridcell_20km "Caloric Variability"
					  ln_post1500MaxCal_20km "Caloric Suitability"
		_Iv20Xln_po_2 "Mediterranean $\times$ \emph{ln}(\emph{post}-1500 Max. Caloric Variance -- \emph{20km})"
		_Iv20Xln_po_3 "East Eurasia  $\times$ \emph{ln}(\emph{post}-1500 Max. Caloric Variance -- \emph{20km})"
		_Iv20Xln_po_4 "Insular Pacific $\times$ \emph{ln}(\emph{post}-1500 Max. Caloric Variance -- \emph{20km})"
		_Iv20Xln_po_5 "North America $\times$ \emph{ln}(\emph{post}-1500 Max. Caloric Variance -- \emph{20km})"
		_Iv20Xln_po_6 "South America $\times$ \emph{ln}(\emph{post}-1500 Max. Caloric Variance -- \emph{20km})"
		anycouncil 	  "Any Council (0/1)"
		v157		  "Political Integration"
		)
		;
	#d cr
		
			
			
****************
*** FIGURES ****
****************


//1. Any Council, Columbian Exchange, & post-1500 Caloric Variability

		estimates clear

		use analysis,clear
		

		preserve
			
			qui xi: reg anycouncil is_post1500MaxCal_gridcell_20km `full_controls', r
			
			estimates store A
			
		restore
		
		preserve
			
			qui xi: reg anycouncil is_prepost_variability_20km `full_controls', r
			
			estimates store B
		
		restore
		
		preserve
			
			qui xi: reg anycouncil is_post1500MaxCal_gridcell_40km `full_controls', r
			
			estimates store C
			
		restore
		
		preserve
			
			qui xi: reg anycouncil is_prepost_variability_40km `full_controls', r
			
			estimates store D
		
		restore
		
			preserve
			
			qui xi: reg anycouncil is_post1500MaxCal_gridcell_60km `full_controls', r
			
			estimates store E
			
		restore
		
		preserve
			
			qui xi: reg anycouncil is_prepost_variability_60km `full_controls', r
			
			estimates store F
		
		restore
		
		preserve
			
			qui xi: reg anycouncil is_post1500MaxCal_gridcell_80km `full_controls', r
			
			estimates store G
			
		restore
		
		preserve
			
			qui xi: reg anycouncil is_prepost_variability_80km `full_controls', r
			
			estimates store H
		
		restore
		
		
		
		coefplot  (A,  pstyle(p2) mlabcolor(black) mlabposition(1) mlabgap(*2) mlabel("{it:p} = " + string(@pval,"%9.2f"))) (B,   pstyle(p3) mlabcolor(black) mlabposition(1) mlabgap(*2) mlabel("{it:p} = " + string(@pval,"%9.2f"))) (C,  pstyle(p2) mlabcolor(black) mlabposition(1) mlabgap(*2) mlabel("{it:p} = " + string(@pval,"%9.2f"))) ///
		(D,   pstyle(p2) mlabcolor(black) mlabposition(1) mlabgap(*2) mlabel("{it:p} = " + string(@pval,"%9.2f"))) (E,   pstyle(p2) mlabcolor(black) mlabposition(1) mlabgap(*2) mlabel("{it:p} = " + string(@pval,"%9.2f"))) ///
		(F,   pstyle(p2) mlabcolor(black) mlabposition(1) mlabgap(*2) mlabel("{it:p} = " + string(@pval,"%9.2f"))) (G,   pstyle(p2) mlabcolor(black) mlabposition(1) mlabgap(*2) mlabel("{it:p} = " + string(@pval,"%9.2f"))) ///
		(H,   pstyle(p2) mlabcolor(black) mlabposition(1) mlabgap(*2) mlabel("{it:p} = " + string(@pval,"%9.2f"))), keep(is_prepost_variability_*  is_post1500MaxCal_gridcell_* ) xline(0) xtitle(Point Estimate)   plotregion(fcolor(white)) graphregion(fcolor(white)) legend(off) ciopts(recast(rcap) lcolor(black))  mcolor(red)
	
		/*graph export "FigA1.png", replace*/
		
		
exit